$().ready(function(){
	//登录操作
	$("input[name=commit]").click(function(){
		var email = $("input[name=email]").val();//登录email
		var passwd = $("input[name=password]");//密码
		var remember_username = $("input[name=remember_username]:checked").val();//记住帐号
		var auto_login = $("input[name=auto_login]:checked").val();//下次自动登录
		if(remember_username == undefined){
			remember_username = 0;
		}
		if(auto_login == undefined){
			auto_login = 0;
		}
		var redirect = $.getUrlParam('redirect');
		//alert(remember_username+'/'+auto_login+'/'+passwd.val()+'/'+email)
		_data = {'redirect':redirect,'email':email,'passwd':passwd.val(),'remember_username':remember_username,'auto_login':auto_login}
//		alert(_data.auto_login+_data.email+_data.passwd+_data.remember_username)
		//alert(redirect);
		var message = $("#message_span");
		$father = $(this);
		$father.attr("disabled",true);
			$.ajax({
				type: "POST",
				url: $.getProjectName()+"/account/checkAccount",
				data:_data,
				dataType:"json",
				success: function(json){
					//alert(json.success+json.message);
					if(json.success == true){
						message.css('color','green');
						message.html(json.message);
//						alert(json.redirect);
						window.location.href=$.getProjectName()+json.redirect;
					}
					if(json.success == false){
						$("#message_span").html(json.message);
						$father.attr('disabled',false);
					}
			},
			error : function(data, status, e){
				alert(alert(e+"\\登录失败，请重试"));
			}
	    });
	});
	$.getProjectName = function (){  
	    //获取当前网址，如： http://localhost:8083/uimcardprj/share/meun.jsp  
	    var curWwwPath=window.document.location.href;  
	    //获取主机地址之后的目录，如： uimcardprj/share/meun.jsp  
	    var pathName=window.document.location.pathname;  
	    var pos=curWwwPath.indexOf(pathName);  
	    //获取主机地址，如： http://localhost:8083  
	    var localhostPaht=curWwwPath.substring(0,pos);  
	    //获取带"/"的项目名，如：/uimcardprj  
	    var projectName=pathName.substring(0,pathName.substr(1).indexOf('/')+1);  
	    return(projectName);  
	} 
	/*
	获取指定的URL参数值
	URL:http://www.blogjava.net/blog?name=bainian
	参数：paramName URL参数
	调用方法:getParam("name")
	返回值:bainian
	*/
	//1.
	$.getUrlParam = function(name){
		var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
		var r = window.location.search.substr(1).match(reg);
		if (r!=null) return unescape(r[2]); return null;
	}
	
});